require("./../../js/jquery-nestable2/jquery.nestable.min.js");
import "./../../js/jquery-nestable2/jquery.nestable.min.css";
require("./../../js/select2/select2.min.js");
require("./../../js/select2/i18n/zh-CN.js");
import { requestPost } from "./../../js/base/utils";
import widgets from "./../../js/base/widgets";

import $ from 'jquery';
global.$ = global.jQuery = $;

(function ($) {
    widgets($);
    
    $(".mypoppage").popPage({
        width:"600px",
        height:"500px"
    })

    $('.select2').select2({"allowClear":true,"placeholder":{"id":"","text":"\u7236\u7ea7\u83dc\u5355"}});

    $('#menu-tree').nestable({maxDepth:3, scroll:true});
    $('.dd').nestable('collapseAll');

    $('.menu-tree-tools').on('click', function(e){
        var action = $(this).data('action');
        if (action === 'expand') {
            $('.dd').nestable('expandAll');
        }
        if (action === 'collapse') {
            $('.dd').nestable('collapseAll');
        }

        $('.menu-tree-tools').removeClass("active");
        $(this).addClass("active");

    });

    $("#menuSortSave").click(function(){
        var serialize = $('#menu-tree').nestable('serialize');
        requestPost(admin_api_menu_updateSort, serialize);
    });
})(jQuery);
